package dao

import (
	"familytree/models"
)

//通过gorm对数据库进行增删改添操作
func Selectpeople() ([]models.Peoples, error) {
	var People []models.Peoples
	err := db.Table("peoples").Order("p_id ASC").Find(&People).Error //查询所有数据并按照升序输出
	return People, err
}

func Addpeople(Peoples models.Peoples) error {
	err := db.Table("peoples").Create(&Peoples).Error //插入一行从前端发送过来的数据并且向数据库里添加新的元组
	return err
}
func Updatepeople(Peoples models.Peoples) error {
	err := db.Table("peoples").Where("p_id = ?", Peoples.P_id).Updates(&Peoples).Error //根据前端传来的数据选择与其车牌号一致的元组进行更改
	return err
}
func Deletepeople(id string) error {
	err := db.Table("peoples").Where("p_id = ?", id).Delete(models.Peoples{}).Error //根据前端输入的id进行删除
	return err
}
